package mahjong;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/** A class representing the time used in player a Mahojong game. */
public class GameTime {

	/**int to store the time */
	private static int time;
	
	
	public static javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() {
		public void actionPerformed(ActionEvent e) 
		{
			time++;
		}
	});;
	
	/**
	 * Set time to parameter t
	 * @param t time
	 */
	public static void setTime(int t)
	{
		time =t;
	}

	/**
	 * get the integer value of the game time
	 * @return time as an int
	 */
	public static int timeToInt()
	{
		return time;
	}

	/**
	 * add a second to the game time
	 */
	public static void addSecond()
	{
		time ++;
	}
	
	/** time string to print out in
	 * 00:00:00 format
	 * @return String representing time hh:mm:ss
	 */ 
	public static String getTimeString()
	{		 
		 return TimeFormater.formatTime(time);
	}

	
	/** Reset the timer. */
	public static void resetTimer()
	{
		time = 0;
		timer.stop();
	}
	
	/** Set current time. 
	 * @param t time to set the timer to
	 * 
	 */
	public static void setTimer(int t)
	{
		timer.stop();
		time = t;
	}
	
	/** Stop the timer. */
	public static void stopTimer()
	{
		timer.stop();
	}
	
	/** Start the timer. */
	public static void startTimer()
	{
		timer.start();
	}
}
